package com.hzhc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzhc.entity.TbSequence;
import com.hzhc.mapper.TbSequenceMapper;
import com.hzhc.service.TbSequenceService;
import org.springframework.stereotype.Service;

/**
 * 全局seq表  服务实现类
 *
 * @author YJT
 */
@Service
public class TbSequenceServiceImpl extends ServiceImpl<TbSequenceMapper, TbSequence> implements TbSequenceService {

    @Override
    public String hcseq_next_dayvalSuffix(Integer suffix, String tabIdname) {
        int nowNum = baseMapper.hcseq_nextval_day(tabIdname);
        StringBuilder builder = getBuilder(suffix,nowNum);
        return builder.toString();
    }

    public StringBuilder getBuilder(Integer suffix, int nowNum) {
        StringBuilder builder = new StringBuilder();
        StringBuilder num = new StringBuilder();
        if (suffix == 2) {
            if (nowNum < 10) {
                num.append("0").append(nowNum);
            } else {
                num.append(nowNum);
            }
        }else if (suffix == 3) {
            if (nowNum < 10) {
                num.append("00").append(nowNum);
            } else if (nowNum < 100) {
                num.append("0").append(nowNum);
            } else {
                num.append(nowNum);
            }
        } else if (suffix == 4) {
            if (nowNum < 10) {
                num.append("000").append(nowNum);
            } else if (nowNum >= 1000) {
                num.append(nowNum);
            } else if (nowNum < 100) {
                num.append("00").append(nowNum);
            } else {
                num.append("0").append(nowNum);
            }
        } else if (suffix == 5) {
            if (nowNum < 10) {
                num.append("0000").append(nowNum);
            } else if (nowNum >= 10000) {
                num.append(nowNum);
            } else if (nowNum < 100) {
                num.append("000").append(nowNum);
            } else if (nowNum < 1000) {
                num.append("00").append(nowNum);
            } else {
                num.append("0").append(nowNum);
            }
        } else if (suffix == 6) {
            if (nowNum < 10) {
                num.append("00000").append(nowNum);
            } else if (nowNum >= 100000) {
                num.append(nowNum);
            } else if (nowNum < 100) {
                num.append("0000").append(nowNum);
            } else if (nowNum < 1000) {
                num.append("000").append(nowNum);
            } else if (nowNum < 10000) {
                num.append("00").append(nowNum);
            } else {
                num.append("0").append(nowNum);
            }
        } else {
            if (nowNum < 10) {
                num.append("00").append(nowNum);
            } else if (nowNum >= 100) {
                num.append(nowNum);
            } else {
                num.append("0").append(nowNum);
            }
        }
        builder.append(num);
        return builder;
    }
}
